﻿using NPOI.OpenXmlFormats.Spreadsheet;
using SmartPlant.Model;
using SmartPlant.Model.Biz;
using SmartPlant.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using static System.Formats.Asn1.AsnWriter;

namespace SmartPlant.Services
{
    public class UnitTagConvService : BaseService, IUnitTagConvService
    {
        public async Task<List<UnitTagConvention>> GetUnitTagConventionsAsync(decimal proId, decimal unitid, ObjectDefId defId)
        {


            if (!_cache.TryGetValue($"{proId}_{unitid}_{defId.ToString()}", out var data))
            {
                string uri = $"/api/Project/{proId}/unit-tag-conv-api/{unitid}/{defId}";
                var res = await GetAsync<List<UnitTagConvention>>(uri);
                _cache[$"{proId}_{unitid}_{defId.ToString()}"] = res.data;// 将数据添加到缓存中  
                return res.data;
            }
            else
            {
                return data;
            }
        }

        /// <summary>
        /// key 为projid + "_" + unitid + “_” + objectdefid
        /// </summary>
        private readonly static Dictionary<string, List<UnitTagConvention>> _cache = new Dictionary<string, List<UnitTagConvention>>();
    }
}
